<?php
/**
 * This file is part of DomAr.
 * 
 * DomAr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomAr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomAr.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */

/**
 * @package DomAr
 * @subpackage DomArChangeLog
 * 
 * @orm tablename domar_changelog
 * @orm index(objectId,objectClassName,propertyName,datetime)
 */
class DomArChangeLogItem extends DomArObject {
	
	/**
	 * @orm char(15)
	 */
	public $ip;
	/**
	 * @orm plugin DomArDateTime(now)
	 */
	public $datetime;
	/**
	 * @orm int(11)
	 */
	public $objectId;
	/**
	 * @orm char(255)
	 */
	public $objectClassName;
	/**
	 * @orm char(255)
	 */
	public $propertyName;
	/**
	 * @orm char(50000)
	 */
	public $value;
	
	/**
	 * Prepare log item. Use this method for setting custom properties like logged in user id...
	 */
	public function prepare( DomArObject $object ) {
		
	}
	/**
	 * Prepare object old property value for storage.
	 *
	 * @param DomArObject $object
	 * @param Mixed $oldPropertyValue
	 * @return String
	 */
	public function parseValue( DomArObject $object, &$oldPropertyValue ) {
		$set = new DomArInsertValueSet();
		$object->getProperty( $this->propertyName )->update( $object, $oldPropertyValue, $set );
		$values = explode(',',$set->getValues());
		
		// try to escape mysql query params
		foreach( $values as &$value ) {
			if( $value == 'NULL')
				$value = NULL;
			else if( $value[0] == '\'' && substr($value,-1,1) == '\'')
				$value = substr($value,1,-1);
			else
				$value = (string)$value;
		}
		
		return $value;
	}

}
?>